<title>设置我的资料</title>

<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>设置</cite></a>
    <a><cite>基础设置</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header">基础设置</div>
        <div class="layui-card-body" pad15>

          <div class="layui-form" lay-filter="setmyinfo">
            <div class="layui-form-item">
              <label class="layui-form-label">首页标题</label>
              <div class="layui-input-inline" style="width: 350px;">
                <input type="text" name="index_title" value="" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">首页关键词</label>
              <div class="layui-input-inline" style="width: 350px;">
                <input type="text" name="index_keywords" value="" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">首页描述</label>
              <div class="layui-input-inline">
                <textarea name="index_description" placeholder="请输入内容" class="layui-textarea" style="width: 350px;"></textarea>
              </div>
            </div>

            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="setmyinfo">提交</button>
                <!-- <button type="reset" class="layui-btn layui-btn-primary">重新填写</button> -->
              </div>
            </div>
          </div>

        </div>
      </div>
    </div>
  </div>
</div>

<script>
  layui.use(['form', 'upload'], function (exports) {
    var $ = layui.$
      , layer = layui.layer
      , laytpl = layui.laytpl
      , setter = layui.setter
      , view = layui.view
      , admin = layui.admin
      , form = layui.form
      , upload = layui.upload
      , lang = layui.data('lang').lang;

    var $body = $('body');

    group = lang;


    /**
     *  为form表单初始赋值
     */
    var index = layer.load({ shade: [0.4, '#def'], icon: '&#xe63d' });
    $(".layui-form").hide();

    $.ajax({
      url: '/api/setting/getSettingList',
      type: "GET",
      dataType: 'json',
      data: {
        group: group,
      },
      success: function (res) {
        if (res.code == 0) {
          console.log(res.data);
          form.val("setmyinfo", res.data);
          // form.render();
          $(".layui-form").show();
          layer.close(index);
        }
      }
    });

    form.render();

    //自定义验证
    form.verify({
      nickname: function (value, item) { //value：表单的值、item：表单的DOM对象
        if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
          return '用户名不能有特殊字符';
        }
        if (/(^\_)|(\__)|(\_+$)/.test(value)) {
          return '用户名首尾不能出现下划线\'_\'';
        }
        if (/^\d+\d+\d$/.test(value)) {
          return '用户名不能全为数字';
        }
      }

      //我们既支持上述函数式的方式，也支持下述数组的形式
      //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
      , pass: [
        /^[\S]{6,12}$/
        , '密码必须6到12位，且不能出现空格'
      ]

      //确认密码
      , repass: function (value) {
        if (value !== $('#LAY_password').val()) {
          return '两次密码输入不一致';
        }
      }
    });

    //网站设置
    form.on('submit(set_website)', function (obj) {
      layer.msg(JSON.stringify(obj.field));

      //提交修改
      /*
      admin.req({
        url: ''
        ,data: obj.field
        ,success: function(){
          
        }
      });
      */
      return false;
    });

    //邮件服务
    form.on('submit(set_system_email)', function (obj) {
      layer.msg(JSON.stringify(obj.field));

      //提交修改
      /*
      admin.req({
        url: ''
        ,data: obj.field
        ,success: function(){
          
        }
      });
      */
      return false;
    });


    //设置我的资料
    form.on('submit(setmyinfo)', function (obj) {
      var buttonObj = $(this);
      // layer.msg(JSON.stringify(obj.field));

      //提交修改
      console.log(obj);
      console.log(JSON.stringify(obj.field));

      $(this).html('正在提交...').addClass('layui-btn-disabled');

      admin.req({
        url: '/api/Setting/myUpdate/group/' + layui.data('lang').lang
        , data: obj.field
        , success: function (res) {
          layer.msg(res.msg, { icon: 1, time: 800 });
          if (res.code == 0) {
            buttonObj.html('提交').removeClass('layui-btn-disabled');
          } else {

          }
        }
      });

      return false;
    });

    //设置密码
    form.on('submit(setmypass)', function (obj) {
      layer.msg(JSON.stringify(obj.field));

      //提交修改
      /*
      admin.req({
        url: ''
        ,data: obj.field
        ,success: function(){
          
        }
      });
      */
      return false;
    });


  });
</script>